#include <iostream>
#include <vector>
using namespace std;
#include <iostream>
#include <vector>
using namespace std;

class Friend_Circle{
private:
    vector<vector<int>> Matrix;
    vector<bool> visited;
    int node_num;
public:
    Friend_Circle(vector<vector<int>>& M,vector<bool> &v,int i);
    void DFS(int i);
    int Find_CircleNum();
};
Friend_Circle::Friend_Circle(vector<vector<int>> &M,vector<bool> &v,int i) {
    Matrix = M;
    visited = v;
    node_num = i;
}
void Friend_Circle::DFS(int i) {
    int N = Matrix[i].size();
    for(int j = 0;j < N;j++)
    {
        int visited_index = Matrix[i][j];
        cout<<"visited: "<<visited_index<<endl;
        if(visited[visited_index] == true)
        {
            visited[visited_index] = false;
            if(Matrix[i][j] != 0)
                DFS(Matrix[i][j]);
            else
                break;
        }
    }
}
int Friend_Circle::Find_CircleNum() {
    int N = Matrix.size();
    int circle = 0; //朋友圈数
    for(int i = 0;i < N;i++)
    {
        if(visited[i] == true) //还没被遍历过
        {
            //dfs(M,visit,i); //使用dfs搜索并标记与其相关的学生
            DFS(i);   //使用bfs搜索并标记与其相关的学生
            circle++;
        }
        cout<<circle<<"\n";
    }
    return circle;
}
int main() {
    vector<vector<int>> v;
    vector<int> v1 = {0};
    vector<int> v2 = {5,3,0};
    vector<int> v3 = {8,4,0};
    vector<int> v4 = {9,0};
    vector<int> v5 = {9,0};
    vector<int> v6 = {3,0};
    vector<int> v7 = {0};
    vector<int> v8 = {7,9,0};
    vector<int> v9 = {0};
    vector<int> v10 = {9,7,0};
    vector<bool> visited(10,true);
    v.push_back(v1);
    v.push_back(v2);
    v.push_back(v3);
    v.push_back(v4);
    v.push_back(v5);
    v.push_back(v6);
    v.push_back(v7);
    v.push_back(v8);
    v.push_back(v9);
    v.push_back(v10);
    Friend_Circle f = Friend_Circle(v,visited,0);
    int num = f.Find_CircleNum();
    cout<<num<<"\n";

    return 0;
}